615D - Multipliers - CodeForces Solution


math number theory *2000

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll b1[200010], a1[200010];

ll bigmod(ll x, ll y, ll mod){
    ll i, j, res=1;
    while(y>0){
        if(y%2==1){
            res=(res*x)%mod;
        }
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}

int main(){
    ll n, i, k, x, y, p, q, ii, jj, j, t, a[200010];
    //scanf("%lld", &t);
    //while(t--){
        scanf("%lld", &n);
        ll ans=1;
        ll mod=1e9+7;
        for(i=0; i<n; i++){
            scanf("%lld", &a[i]);
            ans=(ans*a[i])%mod;
            a1[a[i]]++;
        }
        n=200000;
        ii=0;
        for(i=2; i<=n; i++){
            if(a1[i]%2==1) ii=1;
        }
        if(ii==1){
            //printf("88");
            ll mod1=1e9+6;
            for(i=2; i<=n; i++){
                if(a1[i]%2==1){
                    jj=(a1[i]+1)/2;
                    a1[i]=0;
                    break;
                }
            }
            //printf("%lld\n", jj);
            for(i=2; i<=n; i++){
                if(a1[i]>0) jj=(jj*(a1[i]+1))%mod1;
                //printf("0000 %lld\n", jj);
            }
            //printf("%lld %lld\n", ans, jj);
            ans=bigmod(ans, jj, mod);
            printf("%lld\n", ans);
            return 0;
        }
        ll mod1=1e9+6;
        jj=1;
        for(i=2; i<=n; i++){
            if(a1[i]>0) jj=(jj*(a1[i]+1))%mod1;
        }
        //printf("66 %lld\n", jj);
        for(i=2; i<=n; i++){
            a1[i]=a1[i]/2;
        }
        ans=1;
        for(i=2; i<=n; i++){
            if(a1[i]>0){
                x=bigmod(i, a1[i], mod);
                ans=(ans*x)%mod;
            }
        }
        //printf("77 %lld %lld\n", ans, jj);
        ans=bigmod(ans, jj, mod);
        printf("%lld\n", ans);
    //}
    return 0;
}


Comments

Submit
0 Comments
More Questions

1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer
1358C - Celex Update
1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees